package com.newtouch.bxzs.business.personal.controller;

import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.personal.model.ModifyUserPersonalInfoVO;
import com.newtouch.bxzs.business.personal.model.PersonalVisibleVO;
import com.newtouch.bxzs.business.personal.model.UserPersonalInfoBO;
import com.newtouch.bxzs.business.personal.service.PersonalService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户个人信息控制器
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月28日</td>
 * <td>xiongdianqiang</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author xiongdianqiang
 *
 * @version 1.0.0
 * @since 1.0.0
 */
@RestController
@SuppressWarnings("unchecked")
@Api(tags = "维护个人信息")
@RequestMapping(value = "/personalController")
public class PersonalController {
	@Autowired
	private PersonalService personalService;

	/** 静态变量：系统日志 */
	private static final Log logger = LogFactory.getLog(PersonalController.class);

	@ApiOperation("获取个人信息")
	@GetMapping(value = "/getPersonalDetail")
	@MyLog(systemFunctionName = "维护个人信息", systemFunctionUrl = "/personalController/getPersonalDetail", userOperationType = 4, userOperationSummary = "获取个人信息")
	public BaseResponse<UserPersonalInfoBO> getPersonalDetail() {
		logger.info("查询用户个人信息");
		return RespGenerator.returnOK(personalService.getPersonalDetail());
	}

	@ApiOperation("更改个人信息")
	@PostMapping(value = "/updatePersonalDetail")
	@MyLog(systemFunctionName = "维护个人信息", systemFunctionUrl = "/personalController/updatePersonalDetail", userOperationType = 2, userOperationSummary = "更改个人信息")
	public BaseResponse<String> updatePersonalDetail(@RequestBody ModifyUserPersonalInfoVO userPersonalInfoVO) {
		logger.info("更改用户个人信息");
		personalService.updatePersonalDetailById(userPersonalInfoVO);
		return RespGenerator.returnOK("成功！");
	}

	@ApiOperation("更改个人名片信息")
	@PostMapping(value = "/updatePersonalCard")
	@MyLog(systemFunctionName = "维护个人信息", systemFunctionUrl = "/personalController/updatePersonalCard", userOperationType = 2, userOperationSummary = "更改个人名片信息")
	public BaseResponse<String> updatePersonalCard(@RequestBody PersonalVisibleVO personalVisibleVO) {
		logger.info("更改用户名片信息");
		personalService.updatePersonalCardById(personalVisibleVO);
		return RespGenerator.returnOK("成功！");
	}

	@ApiOperation("设置/修改手势密码")
	@GetMapping("/modifyHandPass")
	public BaseResponse<Integer> modifyHandPass(@RequestParam("handPass") String handPass, @RequestParam("confirmHandPass") String confirmHandPass) {
		return RespGenerator.returnOK(personalService.modifyHandPass(handPass, confirmHandPass));
	}

	@ApiOperation("开启/关闭手势密码")
	@GetMapping("/enableHandPass")
	public BaseResponse<Integer> enableHandPass(@RequestParam("handPassEnable") Boolean handPassEnable) {
		return RespGenerator.returnOK(personalService.enableHandPass(handPassEnable));
	}

	@ApiOperation("忘记手势密码时,校验登录密码是否正确")
	@GetMapping("/checkLoginPassword")
	public BaseResponse<Boolean> checkLoginPassword(@RequestParam("password") String password) {
		return RespGenerator.returnOK(personalService.checkLoginPassword(password));
	}

	@ApiOperation("校验手势密码是否正确")
	@GetMapping("/checkHandPass")
	public BaseResponse<Boolean> checkHandPass(@RequestParam("password") String password) {
		return RespGenerator.returnOK(personalService.checkHandPass(password));
	}

	@ApiOperation("修改登录密码")
	@GetMapping("/updateLoginPassword")
	public BaseResponse<Integer> updateLoginPassword(@RequestParam("password") String password, @RequestParam("confirmPassword") String confirmPassword) {
		return RespGenerator.returnOK(personalService.updateLoginPassword(password, confirmPassword));
	}

}
